import { useStore } from "@/store/user";
import { Directive } from 'vue'

export const role: Directive = {
    mounted(el, binding) {
        const { value } = binding
        const user = useStore()
        console.log("🚀 ~ 自定义指令 绑定的", value)
        const super_admin = "ROOT";

        const roles: Array<string> = user.roles
        console.log("🚀 ~ 获得的角色", roles)

        if (value && value instanceof Array && value.length > 0) {
            const roleFlag = value
            const hasRole = roles.some(role => {
                return super_admin === role || roleFlag.includes(role)
            })

            if (!hasRole) {
                console.log("🚀 没有对应的角色")
                // el.parentNode && el.parentNode.removeChild(el)
            }
        } else {
            throw new Error(`请设置角色权限标签值"`)
        }
    }
}
